<?php
  include("./dbconn.php");

  $user = $_GET["user"];
  $pw = $_GET["pw"];

   //用户名是否被占用
   $sql = "select * from user where user='$user'";

   $result = $conn->query($sql);

   if ($result->num_rows > 0){
    //  被占用
     $data['code'] = 1;
     $data['msg'] = '用户名被占用';
   }else{
    //用户名可以注册
      $sql = "insert into user (user,pw) values ('$user','$pw')";
      if ($conn->query($sql) === true){
        //成功
        $data['code'] = 0;
        $data['msg'] = '注册成功';
      }else{
         //失败
         $data['code'] = 2;
         $data['msg'] = '注册失败';
      }
   }

   echo json_encode($data);
?>